import Banner from "../../Banner";
import NodeUtil from "../Utils/NodeUtil";

const { ccclass, property, menu } = cc._decorator;

@ccclass
@menu("Framework/UI组件/Panel_Loading")
export default class LoadingPanel extends cc.Component {
    LoadingLabel: cc.Label = null;
    LoadingFG: cc.Sprite = null;

    protected onLoad(): void {
        this.LoadingLabel = NodeUtil.GetComponent("LoadingLabel", this.node, cc.Label);
        this.LoadingFG = NodeUtil.GetComponent("LoadingFG", this.node, cc.Sprite);
    }

    Show(scene: string) {
        this.LoadingFG.fillRange = 0;
        this.LoadingLabel.string = `${0}`

        cc.director.preloadScene(scene, (completedCount: number, totalCount: number, item: any) => {
            this.LoadingFG.fillRange = this.LoadingFG.fillRange > completedCount / totalCount ? this.LoadingFG.fillRange : completedCount / totalCount;
            this.LoadingLabel.string = `${Math.ceil(completedCount / totalCount * 100)}`;
        }, () => {
            cc.director.loadScene(scene);
        });
    }
}
